﻿using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x020005A8 RID: 1448
	public class MPLightCtrl : MonoBehaviour
	{
		// Token: 0x1700046F RID: 1135
		// (set) Token: 0x060024D6 RID: 9430 RVA: 0x000DB530 File Offset: 0x000D9730
		public OCILight ociLight
		{
			set
			{
				this.m_OCILight = value;
				if (this.m_OCILight != null)
				{
					this.UpdateInfo();
				}
			}
		}

		// Token: 0x17000470 RID: 1136
		// (get) Token: 0x060024D7 RID: 9431 RVA: 0x000DB54C File Offset: 0x000D974C
		// (set) Token: 0x060024D8 RID: 9432 RVA: 0x000DB55C File Offset: 0x000D975C
		public bool active
		{
			get
			{
				return base.gameObject.activeSelf;
			}
			set
			{
				base.gameObject.SetActive(value);
				if (!base.gameObject.activeSelf)
				{
					if (this.isColorFunc)
					{
						Singleton<Studio>.Instance.colorMenu.updateColorFunc = null;
					}
					this.isColorFunc = false;
				}
			}
		}

		// Token: 0x060024D9 RID: 9433 RVA: 0x000DB59C File Offset: 0x000D979C
		private void UpdateInfo()
		{
			this.isUpdateInfo = true;
			if (this.m_OCILight == null)
			{
				return;
			}
			LightType lightType = this.m_OCILight.lightType;
			if (lightType != LightType.Directional)
			{
				if (lightType != LightType.Point)
				{
					if (lightType == LightType.Spot)
					{
						this.viRange.slider.minValue = 0.5f;
						this.viRange.slider.maxValue = 100f;
					}
				}
				else
				{
					this.viRange.slider.minValue = 0.1f;
					this.viRange.slider.maxValue = 100f;
				}
			}
			this.toggleVisible.isOn = this.m_OCILight.lightInfo.enable;
			this.toggleTarget.isOn = this.m_OCILight.lightInfo.drawTarget;
			this.toggleShadow.isOn = this.m_OCILight.lightInfo.shadow;
			if (this.imageSample)
			{
				this.imageSample.color = this.m_OCILight.lightInfo.color;
			}
			this.viIntensity.slider.value = this.m_OCILight.lightInfo.intensity;
			this.viIntensity.inputField.text = this.m_OCILight.lightInfo.intensity.ToString("0.000");
			this.viRange.slider.value = this.m_OCILight.lightInfo.range;
			this.viRange.inputField.text = this.m_OCILight.lightInfo.range.ToString("0.000");
			this.viSpotAngle.slider.value = this.m_OCILight.lightInfo.spotAngle;
			this.viSpotAngle.inputField.text = this.m_OCILight.lightInfo.spotAngle.ToString("0.000");
			LightType lightType2 = this.m_OCILight.lightType;
			if (lightType2 != LightType.Directional)
			{
				if (lightType2 != LightType.Point)
				{
					if (lightType2 == LightType.Spot)
					{
						this.backgroundInfoDirectional.active = false;
						this.backgroundInfoPoint.active = false;
						this.backgroundInfoSpot.active = true;
						this.backgroundInfoSpot.target = this.m_OCILight.lightTarget;
						this.viRange.active = true;
						this.viSpotAngle.active = true;
					}
				}
				else
				{
					this.backgroundInfoDirectional.active = false;
					this.backgroundInfoPoint.active = true;
					this.backgroundInfoPoint.target = this.m_OCILight.lightTarget;
					this.backgroundInfoSpot.active = false;
					this.viRange.active = true;
					this.viSpotAngle.active = false;
				}
			}
			else
			{
				this.backgroundInfoDirectional.active = true;
				this.backgroundInfoDirectional.target = this.m_OCILight.lightTarget;
				this.backgroundInfoPoint.active = false;
				this.backgroundInfoSpot.active = false;
				this.viRange.active = false;
				this.viSpotAngle.active = false;
			}
			this.isUpdateInfo = false;
		}

		// Token: 0x060024DA RID: 9434 RVA: 0x000DB8D0 File Offset: 0x000D9AD0
		private void OnClickColor()
		{
			Singleton<Studio>.Instance.colorMenu.updateColorFunc = new UI_ColorInfo.UpdateColor(this.OnValueChangeColor);
			this.isColorFunc = true;
			Singleton<Studio>.Instance.colorMenu.SetColor(this.m_OCILight.lightInfo.color, UI_ColorInfo.ControlType.PresetsSample);
			Singleton<Studio>.Instance.colorPaletteCtrl.visible = true;
		}

		// Token: 0x060024DB RID: 9435 RVA: 0x000DB930 File Offset: 0x000D9B30
		private void OnValueChangeColor(Color _color)
		{
			if (this.m_OCILight != null)
			{
				this.m_OCILight.SetColor(_color);
			}
			if (this.imageSample)
			{
				this.imageSample.color = _color;
			}
		}

		// Token: 0x060024DC RID: 9436 RVA: 0x000DB968 File Offset: 0x000D9B68
		private void OnValueChangeEnable(bool _value)
		{
			this.m_OCILight.SetEnable(_value, false);
		}

		// Token: 0x060024DD RID: 9437 RVA: 0x000DB978 File Offset: 0x000D9B78
		private void OnValueChangeDrawTarget(bool _value)
		{
			this.m_OCILight.SetDrawTarget(_value, false);
		}

		// Token: 0x060024DE RID: 9438 RVA: 0x000DB988 File Offset: 0x000D9B88
		private void OnValueChangeShadow(bool _value)
		{
			this.m_OCILight.SetShadow(_value, false);
		}

		// Token: 0x060024DF RID: 9439 RVA: 0x000DB998 File Offset: 0x000D9B98
		private void OnValueChangeIntensity(float _value)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			if (this.m_OCILight.SetIntensity(Mathf.Clamp(_value, 0.1f, 2f), false))
			{
				this.viIntensity.inputField.text = this.m_OCILight.lightInfo.intensity.ToString("0.00");
			}
		}

		// Token: 0x060024E0 RID: 9440 RVA: 0x000DB9FC File Offset: 0x000D9BFC
		private void OnEndEditIntensity(string _text)
		{
			float value = Mathf.Clamp(this.StringToFloat(_text), 0.1f, 2f);
			this.m_OCILight.SetIntensity(value, false);
			this.viIntensity.inputField.text = this.m_OCILight.lightInfo.intensity.ToString("0.00");
			this.viIntensity.slider.value = this.m_OCILight.lightInfo.intensity;
		}

		// Token: 0x060024E1 RID: 9441 RVA: 0x000DBA78 File Offset: 0x000D9C78
		private void OnClickIntensity()
		{
			if (this.m_OCILight.SetIntensity(1f, false))
			{
				this.viIntensity.inputField.text = this.m_OCILight.lightInfo.intensity.ToString("0.00");
				this.viIntensity.slider.value = this.m_OCILight.lightInfo.intensity;
			}
		}

		// Token: 0x060024E2 RID: 9442 RVA: 0x000DBAE8 File Offset: 0x000D9CE8
		private void OnValueChangeRange(float _value)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			if (this.m_OCILight.SetRange(_value, false))
			{
				this.viRange.inputField.text = this.m_OCILight.lightInfo.range.ToString("0.000");
			}
		}

		// Token: 0x060024E3 RID: 9443 RVA: 0x000DBB40 File Offset: 0x000D9D40
		private void OnEndEditRange(string _text)
		{
			float value = Mathf.Max((this.m_OCILight.lightType != LightType.Spot) ? 0.1f : 0.5f, this.StringToFloat(_text));
			this.m_OCILight.SetRange(value, false);
			this.viRange.inputField.text = this.m_OCILight.lightInfo.range.ToString("0.000");
			this.viRange.slider.value = this.m_OCILight.lightInfo.range;
		}

		// Token: 0x060024E4 RID: 9444 RVA: 0x000DBBD4 File Offset: 0x000D9DD4
		private void OnClickRange()
		{
			if (this.m_OCILight.SetRange(30f, false))
			{
				this.viRange.inputField.text = this.m_OCILight.lightInfo.range.ToString("0.000");
				this.viRange.slider.value = this.m_OCILight.lightInfo.range;
			}
		}

		// Token: 0x060024E5 RID: 9445 RVA: 0x000DBC44 File Offset: 0x000D9E44
		private void OnValueChangeSpotAngle(float _value)
		{
			if (this.isUpdateInfo)
			{
				return;
			}
			if (this.m_OCILight.SetSpotAngle(_value, false))
			{
				this.viSpotAngle.inputField.text = this.m_OCILight.lightInfo.spotAngle.ToString("0.000");
			}
		}

		// Token: 0x060024E6 RID: 9446 RVA: 0x000DBC9C File Offset: 0x000D9E9C
		private void OnEndEditSpotAngle(string _text)
		{
			float value = Mathf.Clamp(this.StringToFloat(_text), 1f, 179f);
			this.m_OCILight.SetSpotAngle(value, false);
			this.viSpotAngle.inputField.text = this.m_OCILight.lightInfo.spotAngle.ToString("0.000");
			this.viSpotAngle.slider.value = this.m_OCILight.lightInfo.spotAngle;
		}

		// Token: 0x060024E7 RID: 9447 RVA: 0x000DBD18 File Offset: 0x000D9F18
		private void OnClickSpotAngle()
		{
			if (this.m_OCILight.SetSpotAngle(30f, false))
			{
				this.viSpotAngle.inputField.text = this.m_OCILight.lightInfo.spotAngle.ToString("0.000");
				this.viSpotAngle.slider.value = this.m_OCILight.lightInfo.spotAngle;
			}
		}

		// Token: 0x060024E8 RID: 9448 RVA: 0x000DBD88 File Offset: 0x000D9F88
		private float StringToFloat(string _text)
		{
			float num = 0f;
			return (!float.TryParse(_text, out num)) ? 0f : num;
		}

		// Token: 0x060024E9 RID: 9449 RVA: 0x000DBDB4 File Offset: 0x000D9FB4
		private void Awake()
		{
			this.buttonSample.onClick.AddListener(new UnityAction(this.OnClickColor));
			this.toggleVisible.onValueChanged.AddListener(new UnityAction<bool>(this.OnValueChangeEnable));
			this.toggleTarget.onValueChanged.AddListener(new UnityAction<bool>(this.OnValueChangeDrawTarget));
			this.toggleShadow.onValueChanged.AddListener(new UnityAction<bool>(this.OnValueChangeShadow));
			this.viIntensity.slider.onValueChanged.AddListener(new UnityAction<float>(this.OnValueChangeIntensity));
			this.viIntensity.inputField.onEndEdit.AddListener(new UnityAction<string>(this.OnEndEditIntensity));
			this.viIntensity.button.onClick.AddListener(new UnityAction(this.OnClickIntensity));
			this.viRange.slider.onValueChanged.AddListener(new UnityAction<float>(this.OnValueChangeRange));
			this.viRange.inputField.onEndEdit.AddListener(new UnityAction<string>(this.OnEndEditRange));
			this.viRange.button.onClick.AddListener(new UnityAction(this.OnClickRange));
			this.viSpotAngle.slider.onValueChanged.AddListener(new UnityAction<float>(this.OnValueChangeSpotAngle));
			this.viSpotAngle.inputField.onEndEdit.AddListener(new UnityAction<string>(this.OnEndEditSpotAngle));
			this.viSpotAngle.button.onClick.AddListener(new UnityAction(this.OnClickSpotAngle));
			this.isUpdateInfo = false;
		}

		// Token: 0x0400257B RID: 9595
		[SerializeField]
		private MPLightCtrl.BackgroundInfo backgroundInfoDirectional = new MPLightCtrl.BackgroundInfo();

		// Token: 0x0400257C RID: 9596
		[SerializeField]
		private MPLightCtrl.BackgroundInfo backgroundInfoPoint = new MPLightCtrl.BackgroundInfo();

		// Token: 0x0400257D RID: 9597
		[SerializeField]
		private MPLightCtrl.BackgroundInfo backgroundInfoSpot = new MPLightCtrl.BackgroundInfo();

		// Token: 0x0400257E RID: 9598
		[SerializeField]
		private Image imageSample;

		// Token: 0x0400257F RID: 9599
		[SerializeField]
		private Button buttonSample;

		// Token: 0x04002580 RID: 9600
		[SerializeField]
		private Toggle toggleVisible;

		// Token: 0x04002581 RID: 9601
		[SerializeField]
		private Toggle toggleTarget;

		// Token: 0x04002582 RID: 9602
		[SerializeField]
		private Toggle toggleShadow;

		// Token: 0x04002583 RID: 9603
		[SerializeField]
		private MPLightCtrl.ValueInfo viIntensity;

		// Token: 0x04002584 RID: 9604
		[SerializeField]
		private MPLightCtrl.ValueInfo viRange;

		// Token: 0x04002585 RID: 9605
		[SerializeField]
		private MPLightCtrl.ValueInfo viSpotAngle;

		// Token: 0x04002586 RID: 9606
		private OCILight m_OCILight;

		// Token: 0x04002587 RID: 9607
		private bool isUpdateInfo;

		// Token: 0x04002588 RID: 9608
		private bool isColorFunc;

		// Token: 0x020005A9 RID: 1449
		[Serializable]
		private class BackgroundInfo
		{
			// Token: 0x17000471 RID: 1137
			// (set) Token: 0x060024EB RID: 9451 RVA: 0x000DBF6C File Offset: 0x000DA16C
			public bool active
			{
				set
				{
					if (this.obj.activeSelf != value)
					{
						this.obj.SetActive(value);
					}
				}
			}

			// Token: 0x17000472 RID: 1138
			// (set) Token: 0x060024EC RID: 9452 RVA: 0x000DBF8C File Offset: 0x000DA18C
			public Info.LightLoadInfo.Target target
			{
				set
				{
					this.image.sprite = this.sprit[(int)value];
				}
			}

			// Token: 0x04002589 RID: 9609
			public GameObject obj;

			// Token: 0x0400258A RID: 9610
			public Sprite[] sprit;

			// Token: 0x0400258B RID: 9611
			public Image image;
		}

		// Token: 0x020005AA RID: 1450
		[Serializable]
		private class ValueInfo
		{
			// Token: 0x17000473 RID: 1139
			// (set) Token: 0x060024EE RID: 9454 RVA: 0x000DBFAC File Offset: 0x000DA1AC
			public bool active
			{
				set
				{
					if (this.obj.activeSelf != value)
					{
						this.obj.SetActive(value);
					}
				}
			}

			// Token: 0x0400258C RID: 9612
			public GameObject obj;

			// Token: 0x0400258D RID: 9613
			public Slider slider;

			// Token: 0x0400258E RID: 9614
			public InputField inputField;

			// Token: 0x0400258F RID: 9615
			public Button button;
		}
	}
}
